<?php
/**
 * Created by PhpStorm.
 * User: tangzhixing
 * Date: 2021/4/7
 * Time: 10:19
 */
namespace App\Middleware;

use Asf\Contracts\Middleware\Middleware;
use Asf\Http\JsonResponse;
use Asf\Http\Request;

/**
 * 中间件的说明例子
 * 1：自定义中间件必须实现 MiddleWare
 * 2：定义完成后配置在 /config/definitions.php下的 middleware下，具体配置方法见该文件
 * Class LoginMiddleware
 * @package App\Middleware
 */
class LoginMiddleware implements Middleware
{
    /**
     * 中间件主方法
     * 注意：如果验证通过不做拦截，请返回任意boolean值
     * @return JsonResponse
     */
    public function handle($request, $redis)
    {
        $token = $request->query->get('token') ?? $request->request->get('token');
        if ($token == 'abcde'){
            return true;
        }else{
            return new JsonResponse([
                'msg' => '请先登录'
            ]);
        }

    }
}